$mod186
NAME MP80188
; Interrupt and misc routines for uPD70208 microcomputer system
;
; Filename:	MISC.ASM
;
; Author: 	Law Wen Yong

; This file contains proprietory information and cannot be copied 
; or distributed without prior permission from the author.
;---------------------------------------------------------------------------
; ASM file to initialise all the values as well as add in interrupt rountine to respective interrupt vector
;API:
public	iodefine ; iodefine function is used to initialise everything on the board.
;From Serial.asm
extrn 	Serial_initialise:far,SERIAL_INTR:far
;From Timer.asm
extrn   TIMER2_INTR:far 
;From LCD.asm
extrn LCD_init:far ;initialise


INT_VEC_SEG	SEGMENT		AT 	0H
; Define the interrupt vector locations
; System reserved interrupts
		ORG	0000H
	DIV_ZERO	DD	?	;not defined yet
	SINGLE_STEP	DD	?	;not defined yet
	NMI_INPUT	DD	?	;start of downloaded program
	BRK_3_VEC	DD	?	;not defined yet
	OVERFLOW	DD	?	;not defined yet
	ARRAY_BND	DD	?	;Array Bounds
                ORG     020H
        TIMER0_VEC      DD      ? ;route for timer 0
; Interrupt control unit
		ORG	030H
	INTP0		DD	SERIAL_INTR
	INTP1		DD	?       ;external, not used yet  
	INTP2		DD	?	;external, not used yet
	INTP3		DD	?	;external, not used yet
        NUMERICS        DD      ?       ;
        RSVED           DD      ?       ;system reserved 
        TIMER1_VEC      DD      ?       ;route for timer 1
        TIMER2_VEC      DD      TIMER2_INTR       ;Timer2 Route
           ;Reserved from 050H to 080H     
	       ORG     080H
;Interrupt Vector addrerss from 080h (type 32) to 3fCH (type 255)
;are avaiable for user software interrupt           
; Software interrupts
	SOFT0		DD	? ;TYPE 32
	SOFT1		DD	? ;TYPE 33
	SOFT2		DD	?
	SOFT3		DD	?
	SOFT4		DD	?
	SOFT5		DD	?
	SOFT6		DD	?
	SOFT7		DD	?
INT_VEC_SEG	ENDS




$include(80188.inc) ;stores impt constant to configure 8088
$include (PPI.inc)  ;stores impt constant to configure PPI

MISC_ROUTINE	SEGMENT
ASSUME CS:MISC_ROUTINE

; ---This procdeure initialize the system I/O area and on-chip devices-----
IODEFINE	PROC	FAR
		PUSH	AX
        	PUSH	DX

; Initialize MPCS to MAP peripheral to IO address
         MOV DX, MPCS
         MOV AX, 0083H ;need to set this value to 8083H after you have attached 256k ROM to the microprocessor
         OUT DX, AL   ;remember to change this to AX when ROM is attached.
		 
; Need to initialise MMCS Register to set the starting address of MCS line if you have attached 256k ROM to microprocessor; attached the both MCS0 and MCS1 pin to the enable pin of the ROM


		;MOV  DX, MMCS
		;MOV  AX,  21FCH  ;starting address from 2000H No wait because it is a memory to processor transfer
		;OUT MMCS, AL
		
; PCSBA initial, set the serial port start from 00H
         MOV DX, PCSBA
         MOV AX, 0003H ; Peripheral starting address 3 wait states inserted because it is a processor to IO transfer
         OUT DX, AL
;**********************************************************************************************************************************
		 ; initialise PPI
        MOV AL, config_CWR
		OUT CWR, AL  ;port A, port B and port C(lower) as output and port C(upper) as input
		Mov AL, 00H
		out PortA, AL
		
		; initialise LCD
		CALL FAR PTR LCD_init; ;LCD
;**************************************************************************************************************************************
		
		 ;initialise serial
         CALL FAR PTR serial_initialise
		 ; SCU use INT0, enable INT0		
	        MOV     DX, INT0_CTRL 
  		    XOR	AX,AX ;clear AX
         	OUT	DX,AL ;set this interrupt level to the highest(level 0), set the msk to non-maskable, Level-trigger mode as edge-triggered mode.
		; Mask other Int
                CLI
                MOV	DX,IMKW 
		MOV	AX,0EEH ;mask away other interrupt except int0		
		
	
		OUT 	DX,AL   
		POP	DX
		POP	AX
		RET

IODEFINE endp
MISC_ROUTINE	ENDS

END
